package com.xxxx.server.controller;


import com.xxxx.server.mapper.EmployeeMapper;
import com.xxxx.server.mapper.SalaryMapper;
import com.xxxx.server.pojo.Employee;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Salary;
import com.xxxx.server.pojo.SalaryEmployee;
import com.xxxx.server.service.impl.SalaryServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-08-17
 */
@RestController
@RequestMapping("/salary")
public class SalaryController {
    @Autowired
    private SalaryServiceImpl salaryService;
    

    /**
     * 查询所有的工资账套
     * @return
     */
    @GetMapping("/sob")
    @ApiOperation(value = "工资账套查询")
    public List<Salary> selectSalaryUser() {
        return salaryService.list();
    }

    /**
     * 添加工资账套
     */
    @PostMapping("/sob")
    @ApiOperation(value ="添加工资账套")
    public RespBean addSalary(@RequestBody Salary salary) {
        if (salaryService.addSalary(salary) == 1) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    /**
     * 更新工资账套
     * @param salary
     * @return
     */
    @PutMapping("/sob")
    @ApiOperation(value = "更新工资账套")
    public RespBean updateSalary(@RequestBody Salary salary) {
        if (salaryService.updateSalary(salary) == 1) {
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }
    @DeleteMapping("/sob/{id}")
    @ApiOperation(value = "删除工资账套")
    public RespBean deleteSalary(@PathVariable Integer id) {
        if (salaryService.deleteSalary(id) == 1) {
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }
}
